from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-14 14:06:10.569050
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 14, Feb, 2021
Time: 14:06:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1579
Nobs: 202.000 HQIC: -47.0355
Log likelihood: 2321.19 FPE: 2.06080e-21
AIC: -47.6319 Det(Omega_mle): 1.33406e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.466336 0.139796 3.336 0.001
L1.Burgenland 0.081913 0.071908 1.139 0.255
L1.Kärnten -0.218314 0.060671 -3.598 0.000
L1.Niederösterreich 0.122185 0.166840 0.732 0.464
L1.Oberösterreich 0.239313 0.146885 1.629 0.103
L1.Salzburg 0.202684 0.077434 2.618 0.009
L1.Steiermark 0.103907 0.104305 0.996 0.319
L1.Tirol 0.147087 0.069787 2.108 0.035
L1.Vorarlberg -0.005321 0.064131 -0.083 0.934
L1.Wien -0.125603 0.137746 -0.912 0.362
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.481708 0.169439 2.843 0.004
L1.Burgenland 0.011820 0.087155 0.136 0.892
L1.Kärnten 0.358272 0.073536 4.872 0.000
L1.Niederösterreich 0.127719 0.202218 0.632 0.528
L1.Oberösterreich -0.138951 0.178032 -0.780 0.435
L1.Salzburg 0.199644 0.093853 2.127 0.033
L1.Steiermark 0.208919 0.126422 1.653 0.098
L1.Tirol 0.137621 0.084586 1.627 0.104
L1.Vorarlberg 0.167757 0.077730 2.158 0.031
L1.Wien -0.541965 0.166954 -3.246 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313541 0.062227 5.039 0.000
L1.Burgenland 0.105742 0.032008 3.304 0.001
L1.Kärnten -0.019481 0.027006 -0.721 0.471
L1.Niederösterreich 0.078245 0.074265 1.054 0.292
L1.Oberösterreich 0.291781 0.065383 4.463 0.000
L1.Salzburg -0.002791 0.034468 -0.081 0.935
L1.Steiermark -0.018361 0.046429 -0.395 0.693
L1.Tirol 0.087175 0.031064 2.806 0.005
L1.Vorarlberg 0.109552 0.028547 3.838 0.000
L1.Wien 0.060664 0.061315 0.989 0.322
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.223290 0.070137 3.184 0.001
L1.Burgenland -0.009530 0.036077 -0.264 0.792
L1.Kärnten 0.023498 0.030439 0.772 0.440
L1.Niederösterreich 0.045165 0.083705 0.540 0.589
L1.Oberösterreich 0.378651 0.073694 5.138 0.000
L1.Salzburg 0.092453 0.038849 2.380 0.017
L1.Steiermark 0.183417 0.052331 3.505 0.000
L1.Tirol 0.038157 0.035013 1.090 0.276
L1.Vorarlberg 0.089599 0.032175 2.785 0.005
L1.Wien -0.066500 0.069108 -0.962 0.336
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520313 0.140387 3.706 0.000
L1.Burgenland 0.057008 0.072211 0.789 0.430
L1.Kärnten 0.014377 0.060927 0.236 0.813
L1.Niederösterreich -0.036385 0.167545 -0.217 0.828
L1.Oberösterreich 0.147007 0.147506 0.997 0.319
L1.Salzburg 0.061199 0.077761 0.787 0.431
L1.Steiermark 0.128535 0.104745 1.227 0.220
L1.Tirol 0.209663 0.070082 2.992 0.003
L1.Vorarlberg 0.026658 0.064402 0.414 0.679
L1.Wien -0.118160 0.138327 -0.854 0.393
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162921 0.098770 1.650 0.099
L1.Burgenland -0.017691 0.050805 -0.348 0.728
L1.Kärnten -0.010269 0.042866 -0.240 0.811
L1.Niederösterreich 0.114603 0.117877 0.972 0.331
L1.Oberösterreich 0.390017 0.103778 3.758 0.000
L1.Salzburg -0.020293 0.054709 -0.371 0.711
L1.Steiermark -0.023864 0.073694 -0.324 0.746
L1.Tirol 0.191085 0.049307 3.875 0.000
L1.Vorarlberg 0.039058 0.045310 0.862 0.389
L1.Wien 0.181601 0.097321 1.866 0.062
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.230542 0.127014 1.815 0.070
L1.Burgenland 0.062757 0.065333 0.961 0.337
L1.Kärnten -0.039486 0.055124 -0.716 0.474
L1.Niederösterreich -0.028284 0.151585 -0.187 0.852
L1.Oberösterreich -0.091697 0.133455 -0.687 0.492
L1.Salzburg 0.037885 0.070354 0.538 0.590
L1.Steiermark 0.391202 0.094768 4.128 0.000
L1.Tirol 0.489434 0.063406 7.719 0.000
L1.Vorarlberg 0.164695 0.058267 2.827 0.005
L1.Wien -0.215634 0.125151 -1.723 0.085
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080852 0.153389 0.527 0.598
L1.Burgenland 0.034381 0.078900 0.436 0.663
L1.Kärnten -0.083237 0.066570 -1.250 0.211
L1.Niederösterreich 0.242244 0.183063 1.323 0.186
L1.Oberösterreich -0.011192 0.161168 -0.069 0.945
L1.Salzburg 0.233029 0.084963 2.743 0.006
L1.Steiermark 0.142713 0.114447 1.247 0.212
L1.Tirol 0.068029 0.076573 0.888 0.374
L1.Vorarlberg 0.051244 0.070367 0.728 0.466
L1.Wien 0.247431 0.151139 1.637 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.585660 0.082929 7.062 0.000
L1.Burgenland -0.034230 0.042656 -0.802 0.422
L1.Kärnten -0.011459 0.035991 -0.318 0.750
L1.Niederösterreich -0.020647 0.098972 -0.209 0.835
L1.Oberösterreich 0.294496 0.087134 3.380 0.001
L1.Salzburg 0.019518 0.045935 0.425 0.671
L1.Steiermark 0.002016 0.061875 0.033 0.974
L1.Tirol 0.078208 0.041399 1.889 0.059
L1.Vorarlberg 0.127975 0.038043 3.364 0.001
L1.Wien -0.035749 0.081712 -0.437 0.662
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.138541 0.035737 0.200312 0.256520 0.063462 0.096164 -0.056569 0.167222
Kärnten 0.138541 1.000000 0.012206 0.190504 0.165646 -0.116299 0.155842 0.010270 0.320925
Niederösterreich 0.035737 0.012206 1.000000 0.305645 0.081628 0.214319 0.129227 0.047248 0.365504
Oberösterreich 0.200312 0.190504 0.305645 1.000000 0.299920 0.291561 0.106307 0.081300 0.131403
Salzburg 0.256520 0.165646 0.081628 0.299920 1.000000 0.148527 0.062792 0.088214 -0.007365
Steiermark 0.063462 -0.116299 0.214319 0.291561 0.148527 1.000000 0.102743 0.096732 -0.099560
Tirol 0.096164 0.155842 0.129227 0.106307 0.062792 0.102743 1.000000 0.157416 0.158650
Vorarlberg -0.056569 0.010270 0.047248 0.081300 0.088214 0.096732 0.157416 1.000000 0.043894
Wien 0.167222 0.320925 0.365504 0.131403 -0.007365 -0.099560 0.158650 0.043894 1.000000